class FlexAppGenerator < Rails::Generator::NamedBase
  attr_accessor :flex_src_dir
  
  def manifest
    #This is the directory within the Flex project for your source code
    # Flex Builder 3.0 suggests the use of src
    @flex_src_dir = 'src'

    record do |m|
      
      BASEDIRS.each { |path| m.directory File.join('flex',@flex_src_dir, class_path, file_name,  path) }
      m.template "main_template.mxml", File.join('flex', @flex_src_dir, 'main.mxml')
      m.directory File.join('flex',@flex_src_dir,'components')
      m.directory File.join('flex',@flex_src_dir,'org','genuflex','command')
      m.directory File.join('flex',@flex_src_dir,'org','genuflex','components')
      m.directory File.join('flex',@flex_src_dir,'org','genuflex','control')
      m.directory File.join('flex',@flex_src_dir,'org','genuflex','model')
      m.directory File.join('flex',@flex_src_dir,'org','genuflex','ui')
      m.directory File.join('flex',@flex_src_dir,'org','genuflex','utils')
      m.directory File.join('flex',@flex_src_dir,'org','genuflex','vo')

      m.directory File.join('flex',@flex_src_dir,class_path,file_name,'ui')
      
      m.file File.join('org','genuflex','command','GenuflexCommand.as').to_s, File.join('flex',@flex_src_dir,'org','genuflex','command','GenuflexCommand.as')
      m.file File.join('org','genuflex','components','GenuflexComboBox.as').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexComboBox.as')
      m.file File.join('org','genuflex','components','GenuflexEditWindow.as').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexEditWindow.as')
      m.file File.join('org','genuflex','components','GenuflexListing.as').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexListing.as')
      m.file File.join('org','genuflex','components','GenuflexMultiSelect.mxml').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexMultiSelect.mxml')
      m.file File.join('org','genuflex','components','GenuflexSearchBox.mxml').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexSearchBox.mxml')
      m.file File.join('org','genuflex','components','GenuflexSelectWindow.mxml').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexSelectWindow.mxml')
      m.file File.join('org','genuflex','components','GenuflexText.mxml').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexText.mxml')
      m.file File.join('org','genuflex','components','GenuflexTree.as').to_s, File.join('flex',@flex_src_dir,'org','genuflex','components','GenuflexTree.as')
      m.file File.join('org','genuflex','control','GenuflexCairngormEvent.as'), File.join('flex',@flex_src_dir,'org','genuflex','control','GenuflexCairngormEvent.as')
      m.file File.join('org','genuflex','control','GenuflexController.as'), File.join('flex',@flex_src_dir,'org','genuflex','control','GenuflexController.as')
      m.file File.join('org','genuflex','model','GenuflexModelLocator.as'), File.join('flex',@flex_src_dir,'org','genuflex','model','GenuflexModelLocator.as')
      m.file File.join('org','genuflex','ui','GenuflexManager.as'), File.join('flex',@flex_src_dir,'org','genuflex','ui','GenuflexManager.as')
      m.file File.join('org','genuflex','utils','GenuflexCairngormHelper.as'), File.join('flex',@flex_src_dir,'org','genuflex','utils','GenuflexCairngormHelper.as')
      m.file File.join('org','genuflex','utils','GenuflexDataCache.as'), File.join('flex',@flex_src_dir,'org','genuflex','utils','GenuflexDataCache.as')
      m.file File.join('org','genuflex','utils','GenuflexDataFormatter.as'), File.join('flex',@flex_src_dir,'org','genuflex','utils','GenuflexDataFormatter.as')
      m.file File.join('org','genuflex','utils','GenuflexDataFunctions.as'), File.join('flex',@flex_src_dir,'org','genuflex','utils','GenuflexDataFunctions.as')
      m.file File.join('org','genuflex','utils','GenuflexLogger.as'), File.join('flex',@flex_src_dir,'org','genuflex','utils','GenuflexLogger.as')
      m.file File.join('org','genuflex','vo','GenuflexValueObject.as'), File.join('flex',@flex_src_dir,'org','genuflex','vo','GenuflexValueObject.as')
      m.file File.join('org','genuflex','vo','BelongsToAssociation.as'), File.join('flex',@flex_src_dir,'org','genuflex','vo','BelongsToAssociation.as')
      m.file File.join('org','genuflex','vo','GenuflexAssociation.as'), File.join('flex',@flex_src_dir,'org','genuflex','vo','GenuflexAssociation.as')
      m.file File.join('org','genuflex','vo','GenuflexMetadata.as'), File.join('flex',@flex_src_dir,'org','genuflex','vo','GenuflexMetadata.as')
      m.file File.join('org','genuflex','vo','HasAndBelongsToManyAssociation.as'), File.join('flex',@flex_src_dir,'org','genuflex','vo','HasAndBelongsToManyAssociation.as')
      m.file File.join('org','genuflex','vo','HasManyAssociation.as'), File.join('flex',@flex_src_dir,'org','genuflex','vo','HasManyAssociation.as')

      m.file "Services_template.mxml", File.join('flex',@flex_src_dir, class_path, file_name, 'business', "Services.mxml")
      m.template "Command_template.as", File.join('flex',@flex_src_dir, class_path, file_name,  'command', "#{file_name.camelcase}Command.as")
      m.template "Controller_template.as", File.join('flex',@flex_src_dir, class_path, file_name,  'control', "#{file_name.camelcase}Controller.as")
      m.template "ModelLocator_template.as", File.join('flex',@flex_src_dir, class_path, file_name, 'model', "#{file_name.camelcase}ModelLocator.as")
      m.template "Delegate_template.as", File.join('flex',@flex_src_dir, class_path, file_name, 'business', "#{file_name.camelcase}Delegate.as")      
      
    end
  end
  
  BASEDIRS = %w(
    business
    command
    control
    model
    vo
  )
  
end
